<script>
	$(function () {
    $('.checkall').on('click', function () {
        $(this).closest('fieldset').find(':checkbox').prop('checked', this.checked);
    });
});
</script>

<%= form_tag users_path, :method => 'get' do%>
	<%= select_tag :field, options_for_select(user_search_params, params[:field]) %>
    <%= text_field_tag :search, params[:search] %>
	<br/>
	<%= select_tag :per_page, options_for_select(results_per_page, params[:per_page]) %> results per page
	<br/>
	
	
	<fieldset>
  <% user_levels.each do |key, value| %>
		<%check_this = true %>
		<%check_this = params[:levels].include?(value) if params[:levels] %>
        <%= check_box_tag 'levels[]', value, check_this -%>
        <%= h key -%>
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
  <% end %>
	<input type="checkbox" class="checkall"> Check all
  </fieldset>
<br/>
<br/>
    <%= submit_tag "Search", :class=>"btn-custom", :name=> nil%> 
	  <input type ="button" class="btn-custom" value="Reset" id="reset"/>
<% end%> 